package com.barbeque.mall.controller;

import com.barbeque.mall.bean.BaseRespVo;
import com.barbeque.mall.bean.BaseRespVoNoData;
import com.barbeque.mall.bean.brand.MarketBrand;
import com.barbeque.mall.bean.category.MarketCategory;
import com.barbeque.mall.bean.category.MarketCategoryCreateBO;
import com.barbeque.mall.bean.category.MarketCategoryCreateVO;
import com.barbeque.mall.bean.category.MarketCategoryL1VO;
import com.barbeque.mall.bean.param.CommonData;
import com.barbeque.mall.service.CategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;



/**
 * @author Tezel
 * @since 2022/07/15 20:28
 */

@RestController
@RequestMapping("admin/category")
public class AdminCategoryController {

    @Autowired
    CategoryService categoryService;



    @RequestMapping("l1")
    public BaseRespVo l1() {


        CommonData<MarketCategoryL1VO> data = categoryService.queryL1();
        BaseRespVo baseRespVo = BaseRespVo.ok(data);
        baseRespVo.setErrmsg("成功");

        return baseRespVo;
    }

    @RequiresPermissions("admin:category:list")
    @RequestMapping("list")
    public BaseRespVo list() {

        CommonData<MarketCategory> data = categoryService.queryList();
        BaseRespVo baseRespVo = BaseRespVo.ok(data);
        baseRespVo.setErrmsg("成功");

        return baseRespVo;
    }


    @RequiresPermissions("admin:category:create")
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody MarketCategoryCreateBO marketCategoryCreateBO) {

        MarketCategoryCreateVO data = categoryService.create(marketCategoryCreateBO);

        BaseRespVo baseRespVo = BaseRespVo.ok(data);
        baseRespVo.setErrmsg("成功");

        return baseRespVo;
    }


    @RequiresPermissions("admin:category:update")
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public BaseRespVoNoData update(@RequestBody MarketCategory marketCategory) {

        categoryService.update(marketCategory);


        return BaseRespVoNoData.ok();
    }


    @RequiresPermissions("admin:category:delete")
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    public BaseRespVoNoData delete(@RequestBody MarketCategory marketCategory) {

        categoryService.delete(marketCategory);

        return BaseRespVoNoData.ok();
    }


}
